#!usr/bin/env python  
# -*- coding:utf-8 _*-
""" 
@author:robot
@file: order_stack.py 
@version:
@time: 2022/11/06 
"""


class ArrayStack:
    def __init__(self, n) -> None:
        """
        :param n: 初始化栈的大小
        """
        self.data = [-1] * n
        self.n = n
        self.count = 0

    def push(self, value):
        # 栈满，无法写入
        if self.n == self.count:
            return False
        self.data[self.count] = value
        self.count += 1
        return True

    def pop(self):
        # 空栈，无法读出
        if self.count == 0:
            return None

        self.count -= 1
        return self.data[self.count]


def test_static():
    array_stack = ArrayStack(5)
    data = ["a", "b", "c", "d", "e"]
    for i in data:
        array_stack.push(i)

    result = array_stack.push("a")
    # 看写入是否失败

    assert not result
    # 看输出是否为输入data的倒叙
    data.reverse()
    for i in data:
        assert i == array_stack.pop()

    assert array_stack.pop() is None

if __name__ == '__main__':
    test_static()